<!doctype html>
<html lang="zh-cn">
<head>

    <meta charset="utf-8">
    <meta name="generator" content="Hugo 0.57.2" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Thymeleaf学习 | The Sky of OtsWang</title>
    <meta property="og:title" content="Thymeleaf学习 - The Sky of OtsWang">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content="2018-12-29T09:59:58&#43;08:00">
        
        
    <meta property="article:modified_time" content="2018-12-29T09:59:58&#43;08:00">
        
    <meta name="Keywords" content="golang,go语言,otswang,java,博客,python">
    <meta name="description" content="Thymeleaf学习">
        
    <meta name="author" content="OtsWang">
    <meta property="og:url" content="https://otswang.gitee.io/hugo/post/java/thymeleaf/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href="/hugo/css/normalize.css">
    
        <link rel="stylesheet" href="/hugo/css/prism.css">
    
    <link rel="stylesheet" href="/hugo/css/style.css">
    <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    


    
    
</head>

<body>
<header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://otswang.gitee.io/hugo/">
                        The Sky of OtsWang
                    </a>
                
                <p class="description">擅长写HelloWorld的小小码农</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    
                    
                    <a  href="https://otswang.gitee.io/hugo/" title="Home">Home</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/tags/" title="Tags">Tags</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/categories/" title="Categories">Categories</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/archives/" title="Archives">Archives</a>
                    
                    <a  href="https://otswang.gitee.io/hugo/about/" title="About">About</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>


<div id="body">
    <div class="container">
        <div class="col-group">

            <div class="col-8" id="main">
                <div class="res-cons">
                    <article class="post">
                        <header>
                            <h1 class="post-title">Thymeleaf学习</h1>
                        </header>
                        <date class="post-meta meta-date">
                            2018年12月29日
                        </date>
                        
                        <div class="post-meta">
                            <span>|</span>
                            
                                <span class="meta-category"><a href="https://otswang.gitee.io/hugo/categories/java">Java</a></span>
                            
                        </div>
                        
                        
                        
                        <div class="post-content">
                            <p>Thymeleaf 是一个Java模板引擎,配合springboot使用很方便. Thymeleaf 可以实现动静分离,但是性能上相对差一些.</p>

<p>Out-of-the-box, Thymeleaf allows you to process six kinds of templates, each of which is called a Template Mode:</p>

<ul>
<li>HTML</li>
<li>XML</li>
<li>TEXT</li>
<li>JAVASCRIPT</li>
<li>CSS</li>
<li>RAW</li>
</ul>

<p>template resolver and template engine</p>

<p>adding an xmlns:th attribute to our <html> tag, something absolutely non-HTML5-ish:</p>

<pre><code class="language-html">&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
</code></pre>

<h3 id="text">text</h3>

<p>so , we can use the attributes <code>th:*</code>.</p>

<p>switch to Thymeleaf’s data attribute syntax, using the data- prefix for attribute names and hyphen (-) separators instead of semi-colons (:):</p>

<h3 id="contexts">contexts</h3>

<h3 id="stard-expression-features">stard expression features</h3>

<ul>
<li>Simple expressions:

<ul>
<li>Variable Expressions: ${&hellip;}</li>
<li>Selection Variable Expressions: *{&hellip;}</li>
<li>Message Expressions: #{&hellip;}</li>
<li>Link URL Expressions: @{&hellip;}</li>
<li>Fragment Expressions: ~{&hellip;}</li>
</ul></li>
<li>Literals

<ul>
<li>Text literals: &lsquo;one text&rsquo;, &lsquo;Another one!&rsquo;,…</li>
<li>Number literals: 0, 34, 3.0, 12.3,…</li>
<li>Boolean literals: true, false</li>
<li>Null literal: null</li>
<li>Literal tokens: one, sometext, main,…</li>
</ul></li>
<li>Text operations:

<ul>
<li>String concatenation: +</li>
<li>Literal substitutions: |The name is ${name}|</li>
</ul></li>
<li>Arithmetic operations:

<ul>
<li>Binary operators: +, -, *, /, %</li>
<li>Minus sign (unary operator): -</li>
</ul></li>
<li>Boolean operations:

<ul>
<li>Binary operators: and, or</li>
<li>Boolean negation (unary operator): !, not</li>
</ul></li>
<li>Comparisons and equality:

<ul>
<li>Comparators: &gt;, &lt;, &gt;=, &lt;= (gt, lt, ge, le)</li>
<li>Equality operators: ==, != (eq, ne)</li>
</ul></li>
<li>Conditional operators:

<ul>
<li>If-then: (if) ? (then)</li>
<li>If-then-else: (if) ? (then) : (else)</li>
<li>Default: (value) ?: (defaultvalue)</li>
</ul></li>
<li>Special tokens:
    No-Operation: _</li>
</ul>

<h3 id="basic-objects">basic objects</h3>

<ul>
<li>#ctx: the context object.</li>
<li>#vars: the context variables.</li>
<li>#locale: the context locale.</li>
<li>#request: (only in Web Contexts) the HttpServletRequest object.</li>
<li>#response: (only in Web Contexts) the HttpServletResponse object.</li>
<li>#session: (only in Web Contexts) the HttpSession object.</li>
<li>#servletContext: (only in Web Contexts) the ServletContext object.</li>
</ul>

<h3 id="utility-objects">utility objects</h3>

<p>_ #execInfo: information about the template being processed.
_ #messages: methods for obtaining externalized messages inside variables expressions, in th_ same way as they would be obtained using #{…} syntax.
_ #uris: methods for escaping parts of URLs/URIs
_ #conversions: methods for executing the configured conversion service (if any).
_ #dates: methods for java.util.Date objects: formatting, component extraction, etc.
_ #calendars: analogous to #dates, but for java.util.Calendar objects.
_ #numbers: methods for formatting numeric objects.
_ #strings: methods for String objects: contains, startsWith, prepending/appending, etc.
_ #objects: methods for objects in general.
_ #bools: methods for boolean evaluation.
_ #arrays: methods for arrays.
_ #lists: methods for lists.
_ #sets: methods for sets.
_ #maps: methods for maps.
_ #aggregates: methods for creating aggregates on arrays or collections.
_ #ids: methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).</p>

<pre><code class="language-html">&lt;p&gt;
  Today is: &lt;span th:text=&quot;${#calendars.format(today,'dd MMMM yyyy')}&quot;&gt;13 May 2011&lt;/span&gt;
&lt;/p&gt;
</code></pre>

<h3 id="selections">selections</h3>

<pre><code class="language-html"> &lt;div th:object=&quot;${session.user}&quot;&gt;
    &lt;p&gt;Name: &lt;span th:text=&quot;*{firstName}&quot;&gt;Sebastian&lt;/span&gt;.&lt;/p&gt;
    &lt;p&gt;Surname: &lt;span th:text=&quot;*{lastName}&quot;&gt;Pepper&lt;/span&gt;.&lt;/p&gt;
    &lt;p&gt;Nationality: &lt;span th:text=&quot;*{nationality}&quot;&gt;Saturn&lt;/span&gt;.&lt;/p&gt;
  &lt;/div&gt;
</code></pre>

<p>or</p>

<pre><code class="language-html">&lt;div&gt;
  &lt;p&gt;Name: &lt;span th:text=&quot;${session.user.firstName}&quot;&gt;Sebastian&lt;/span&gt;.&lt;/p&gt;
  &lt;p&gt;Surname: &lt;span th:text=&quot;${session.user.lastName}&quot;&gt;Pepper&lt;/span&gt;.&lt;/p&gt;
  &lt;p&gt;Nationality: &lt;span th:text=&quot;${session.user.nationality}&quot;&gt;Saturn&lt;/span&gt;.&lt;/p&gt;
&lt;/div&gt;
</code></pre>

<h1 id="一个总结">一个总结</h1>

<h2 id="引用命名空间">引用命名空间</h2>

<pre><code class="language-html">&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt; 
</code></pre>

<p>在html中引入此命名空间，可避免编辑器出现html验证错误，虽然加不加命名空间对Thymeleaf的功能没有任何影响。</p>

<h2 id="输出内容">输出内容</h2>

<pre><code class="language-html">&lt;p th:text=&quot;#{home.welcome}&quot;&gt;Welcome to our grocery store!&lt;/p&gt;
</code></pre>

<p>说明：</p>

<ol>
<li><p><code>th:text</code>  用来将内容输出到所在标签的body中。</p></li>

<li><p><code>#{home.welcome}</code> 用来引入数据home对象中的 welcome属性。</p></li>

<li><p>可以用<code>th:utext</code>用来显示“unescaped ” 的html内容。</p>

<pre><code class="language-html">&lt;p&gt;Today is: &lt;span th:text=&quot;${today}&quot;&gt;13 February 2011&lt;/span&gt;&lt;/p&gt;
</code></pre></li>
</ol>

<p>说明：<code>${today}</code> 用来引用 today 变量</p>

<h2 id="访问对象">访问对象</h2>

<ul>
<li><code>${param.x}</code> 返回名为x 的 request参数。（可能有多个值）</li>
<li><code>${session.x}</code> 返回名为x的Session参数。</li>
<li><code>${application.x}</code> 返回名为 servlet context 的参数。</li>
</ul>

<h2 id="基本语法">基本语法</h2>

<ol>
<li><code>#{home.welcome}</code> &ndash;  访问数据</li>
<li><code>#{home.welcome(${session.user.name})}</code>  &ndash; 格式化数据 当 home.welcome 为 &ldquo;abcdegf{0}&rdquo;  类似这种内容时。（多个参数以逗句分隔）。</li>
<li><code>${today}</code> &mdash; 访问变量</li>
<li>访问基本对象

<ul>
<li><code>#ctx</code>: the context object.</li>
<li><code>#vars</code>: the context variables.</li>
<li><code>#locale</code>: the context locale.</li>
<li><code>#request</code>: (only in Web Contexts) the HttpServletRequest object.</li>
<li><code>#response</code>: (only in Web Contexts) the HttpServletResponse object.</li>
<li><code>#session</code>: (only in Web Contexts) the HttpSession object.</li>
<li><code>#servletContext</code>: (only in Web Contexts) the ServletContext object.</li>
<li>其它公共对象参考: <a href="http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-a-expression-basic-objects">http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-a-expression-basic-objects</a></li>
</ul></li>

<li><p>日期的输出</p>

<pre><code class="language-html">  &lt;span th:text=&quot;${#calendars.format(today,'dd MMMM yyyy')}&quot;&gt;13 May 2011&lt;/span&gt;
</code></pre></li>

<li><p>星号语法</p>

<pre><code class="language-html">  &lt;div th:object=&quot;${session.user}&quot;&gt;
        &lt;p&gt;Name: &lt;span th:text=&quot;*{firstName}&quot;&gt;Sebastian&lt;/span&gt;.&lt;/p&gt;
        &lt;p&gt;Surname: &lt;span th:text=&quot;*{lastName}&quot;&gt;Pepper&lt;/span&gt;.&lt;/p&gt;
        &lt;p&gt;Nationality: &lt;span th:text=&quot;*{nationality}&quot;&gt;Saturn&lt;/span&gt;.&lt;/p&gt;
  &lt;/div&gt;
</code></pre></li>

<li><p>输出URL</p>

<pre><code class="language-html">   &lt;a href=&quot;product/list.html&quot; th:href=&quot;@{/product/list}&quot;&gt;Product List&lt;/a&gt;

   &lt;a href=&quot;details.html&quot; th:href=&quot;@{/order/{orderId}/details(orderId=${o.id})}&quot;&gt;view&lt;/a&gt;
</code></pre></li>

<li><p>使用代码段</p>

<pre><code class="language-html">   &lt;div th:insert=&quot;~{commons :: main}&quot;&gt;...&lt;/div&gt;
</code></pre></li>

<li><p>直接输出内容</p>

<pre><code class="language-html">  &lt;span th:text=&quot;'working web application'&quot;&gt;  &lt;!-- 输出字符 --&gt;

  &lt;span th:text=&quot;2013 + 2&quot;&gt;  &lt;!-- 输出数据表达式--&gt;

  &lt;div th:if=&quot;${user.isAdmin()} == false&quot;&gt;  &lt;!--输出布尔表达式--&gt;

  &lt;span th:text=&quot;'Welcome to our application, ' + ${user.name} + '!'&quot;&gt; &lt;!-- 带变量的--&gt;
</code></pre></li>

<li><p>条件表达式</p>

<pre><code class="language-html">  &lt;tr th:class=&quot;${row.even}? 'even' : 'odd'&quot;&gt;
  ...  
  &lt;/tr&gt;

  &lt;tr th:class=&quot;${row.even}? 'alt'&quot;&gt;
  ...省略 false 结果的表达方式
  &lt;/tr&gt;

  &lt;div th:object=&quot;${session.user}&quot;&gt;
  ...省略 true 结果的表达方式
  &lt;p&gt;Age: &lt;span th:text=&quot;*{age}?: '(no age specified)'&quot;&gt;27&lt;/span&gt;.&lt;/p&gt;
  &lt;/div&gt;

  &lt;span th:text=&quot;${user.name} ?: _&quot;&gt;no user authenticated&lt;/span&gt; --不做任何处理时用下划线 _ 表示
</code></pre></li>

<li><p>格式化</p>

<pre><code class="language-html">  &lt;td th:text=&quot;${{user.lastAccessDate}}&quot;&gt;...&lt;/td&gt; --${{.}}  调用默认的格式化器来输出结果。
</code></pre></li>

<li><p>预处理</p>

<pre><code class="language-html">  &lt;p th:text=&quot;${__#{article.text('textVar')}__}&quot;&gt;Some text here...&lt;/p&gt;  
</code></pre>

<p>说明：thymeleaf 的处理模板内容的顺序与书写顺序无关，只能通过  <strong>${expression}</strong> ，来将需要先一步计算出来后面          要用的变量指定为优化处理。</p></li>
</ol>

<h2 id="设置-attribute-值">设置 Attribute 值</h2>

<ol>
<li><p>设置任何Attribute 的方法</p>

<pre><code class="language-html">  &lt;input type=&quot;submit&quot; value=&quot;Subscribe!&quot; th:attr=&quot;value=#{subscribe.submit}&quot;/&gt;   --设置单个

  &lt;img src=&quot;../../images/gtvglogo.png&quot;  th:attr=&quot;src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}&quot; /&gt;  --一次设置多个
</code></pre></li>

<li><p>设置一些内置的Attribute的方法</p>

<pre><code class="language-html">  &lt;li&gt;&lt;a href=&quot;product/list.html&quot; th:href=&quot;@{/product/list}&quot;&gt;Product List&lt;/a&gt;&lt;/li&gt;

  &lt;form action=&quot;subscribe.html&quot; th:action=&quot;@{/subscribe}&quot;&gt;

  &lt;input type=&quot;submit&quot; value=&quot;Subscribe!&quot; th:value=&quot;#{subscribe.submit}&quot;/&gt;

  &lt;img src=&quot;../../images/gtvglogo.png&quot;  th:src=&quot;@{/images/gtvglogo.png}&quot; th:alt-title=&quot;#{logo}&quot; /&gt; -- 一次设置多个（alt title）的方法
</code></pre>

<p>其它的可用属性：<a href="http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#setting-value-to-specific-attributes">http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#setting-value-to-specific-attributes</a></p></li>

<li><p>设置html里没有指的任何属性的语法</p>

<pre><code class="language-html">        &lt;span th:whatever=&quot;${user.name}&quot;&gt;...&lt;/span&gt;   ---whatever 可以换成任何你想设的属性
</code></pre></li>
</ol>

<h2 id="循环输出的语法">循环输出的语法</h2>

<ol>
<li><p>基本循环</p>

<pre><code class="language-html">&lt;tr th:each=&quot;prod : ${prods}&quot;&gt;

 &lt;td th:text=&quot;${prod.name}&quot;&gt;Onions&lt;/td&gt;
 &lt;td th:text=&quot;${prod.price}&quot;&gt;2.41&lt;/td&gt;
 &lt;td th:text=&quot;${prod.inStock}? #{true} : #{false}&quot;&gt;yes&lt;/td&gt;
&lt;/tr&gt;
</code></pre></li>

<li><p>循环状态的使用</p>

<pre><code class="language-html">&lt;table&gt;
  &lt;tr&gt;
        &lt;th&gt;NAME&lt;/th&gt;
        &lt;th&gt;PRICE&lt;/th&gt;
        &lt;th&gt;IN STOCK&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr th:each=&quot;prod,iterStat : ${prods}&quot; th:class=&quot;${iterStat.odd}? 'odd'&quot;&gt;
        &lt;td th:text=&quot;${prod.name}&quot;&gt;Onions&lt;/td&gt;
        &lt;td th:text=&quot;${prod.price}&quot;&gt;2.41&lt;/td&gt;
        &lt;td th:text=&quot;${prod.inStock}? #{true} : #{false}&quot;&gt;yes&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>关于状态的其它信息的使用详细参考：<a href="http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#keeping-iteration-status">http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#keeping-iteration-status</a></p></li>
</ol>

<h2 id="条件判断">条件判断</h2>

<ol>
<li><p>if 和 unless</p>

<pre><code class="language-html">   &lt;a href=&quot;comments.html&quot; th:href=&quot;@{/comments(prodId=${prod.id})}&quot; th:unless=&quot;${#lists.isEmpty(prod.comments)}&quot;&gt;view&lt;/a&gt;

   &lt;a href=&quot;comments.html&quot;  th:href=&quot;@{/product/comments(prodId=${prod.id})}&quot; th:if=&quot;${not #lists.isEmpty(prod.comments)}&quot;&gt;view&lt;/a&gt;
</code></pre></li>

<li><p>switch 语句</p>

<pre><code class="language-html">&lt;div th:switch=&quot;${user.role}&quot;&gt;
  &lt;p th:case=&quot;'admin'&quot;&gt;User is an administrator&lt;/p&gt;
  &lt;p th:case=&quot;#{roles.manager}&quot;&gt;User is a manager&lt;/p&gt;
  &lt;p th:case=&quot;*&quot;&gt;User is some other thing&lt;/p&gt;    --默认的 case 相当于default
&lt;/div&gt;
</code></pre></li>
</ol>

<h2 id="模板-include">模板 include</h2>

<ol>
<li><p>定义和引用代码块</p>

<p>定义代码块</p>

<pre><code class="language-html">  &lt;!DOCTYPE html&gt;

  &lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  &lt;body&gt;

        &lt;div th:fragment=&quot;copy&quot;&gt;
        &amp;copy; 2011 The Good Thymes Virtual Grocery
        &lt;/div&gt;

  &lt;/body&gt;
  &lt;/html&gt;
</code></pre>

<p>引用代码块</p>

<pre><code class="language-html">  &lt;body&gt;

  ...

  &lt;div th:insert=&quot;~{footer :: copy}&quot;&gt;&lt;/div&gt;

  &lt;/body&gt;
</code></pre>

<p>引用未用fragment 标注的代码块</p>

<pre><code>  &lt;div id=&quot;copy-section&quot;&gt;
  &amp;copy; 2011 The Good Thymes Virtual Grocery
  &lt;/div&gt;

  &lt;body&gt;

  ...

  &lt;div th:insert=&quot;~{footer :: #copy-section}&quot;&gt;&lt;/div&gt;

  &lt;/body&gt;
</code></pre></li>

<li><p><code>th:insert</code> <code>th:replace</code> <code>th:include</code> 之间的区别</p>

<ul>
<li><code>th:insert</code>  &mdash; 插入代码块<br /></li>
<li><code>th:replace</code> &ndash; 替换代码块会替换掉容器标签<br /></li>
<li><code>th:include</code> &mdash;- 和insert相似但只会插入fragment标注body内的内容。</li>
</ul></li>

<li><p>带参数的代码段</p>

<pre><code class="language-html">&lt;div th:fragment=&quot;frag (onevar,twovar)&quot;&gt;
&lt;p th:text=&quot;${onevar} + ' - ' + ${twovar}&quot;&gt;...&lt;/p&gt;
&lt;/div&gt;

 &lt;div th:replace=&quot;::frag (${value1},${value2})&quot;&gt;...&lt;/div&gt;
 &lt;div th:replace=&quot;::frag (onevar=${value1},twovar=${value2})&quot;&gt;...&lt;/div&gt;
</code></pre></li>
</ol>

<h2 id="局部变量的使用示例">局部变量的使用示例</h2>

<pre><code class="language-html">&lt;div th:with=&quot;firstPer=${persons[0]}&quot;&gt;
&lt;p&gt;
The name of the first person is &lt;span th:text=&quot;${firstPer.name}&quot;&gt;Julius Caesar&lt;/span&gt;.
&lt;/p&gt;
&lt;/div&gt;

&lt;div th:with=&quot;firstPer=${persons[0]},secondPer=${persons[1]}&quot;&gt;
&lt;p&gt;
The name of the first person is &lt;span th:text=&quot;${firstPer.name}&quot;&gt;Julius Caesar&lt;/span&gt;.
&lt;/p&gt;
&lt;p&gt;
But the name of the second person is
&lt;span th:text=&quot;${secondPer.name}&quot;&gt;Marcus Antonius&lt;/span&gt;.
&lt;/p&gt;
&lt;/div&gt;
</code></pre>

<h2 id="注释">注释</h2>

<pre><code class="language-html">&lt;!-- ... --&gt;  
</code></pre>

<h1 id="常用标签">常用标签</h1>

<table>
<thead>
<tr>
<th>标签</th>
<th>说明</th>
<th>例子</th>
</tr>
</thead>

<tbody>
<tr>
<td>th:id</td>
<td>id</td>
<td><input th:id+"'xxx'+${collect.id}"/></td>
</tr>

<tr>
<td>th:text</td>
<td>text</td>
<td><p th:text="${collection.description}">description</p></td>
</tr>

<tr>
<td>th:utext</td>
<td>html text</td>
<td><p th:utext="${htmlcontent}">content</p></td>
</tr>

<tr>
<td>th:object</td>
<td>object</td>
<td><div th:object="${session.user}" > </div></td>
</tr>

<tr>
<td>th:value</td>
<td>value</td>
<td><input th:value="${user.name}" /></td>
</tr>

<tr>
<td>th:with</td>
<td>set value</td>
<td><div th:with="isEven=${production.count}%2==0"> </div></td>
</tr>

<tr>
<td>th:style</td>
<td>set style</td>
<td>th:style=&ldquo;&lsquo;display:&lsquo;+@{(${sitrue}?&lsquo;none&rsquo; : &lsquo;inline-block&rsquo;)} + &ldquo;&rdquo;</td>
</tr>

<tr>
<td>th:onclick</td>
<td>onclick</td>
<td>th:onclick=&ldquo;&lsquo;getCollect()&rsquo;&rdquo;</td>
</tr>

<tr>
<td>th:each</td>
<td>for</td>
<td><tr th:each="user, userStat:${users}" > </tr></td>
</tr>

<tr>
<td>th:if</td>
<td>if</td>
<td><a th:if="${userId == collect.userId}" /></td>
</tr>

<tr>
<td>th:unless</td>
<td>if not</td>
<td><a th:href="@{/login}" th:unless=${session.user != null}>Login</a></td>
</tr>

<tr>
<td>th:href</td>
<td>see above</td>
<td>see above</td>
</tr>

<tr>
<td>th:switch</td>
<td>switch</td>
<td><div th:switch="${user.role}" ></td>
</tr>

<tr>
<td>th:case</td>
<td>case</td>
<td><p th:case="admin">Admin</p></td>
</tr>

<tr>
<td>th:fragment</td>
<td>fragment</td>
<td><div th:fragment="alert" ></div></td>
</tr>

<tr>
<td>th:include</td>
<td>inluce</td>
<td><div th:include="layout :: htmlhead" ></div></td>
</tr>

<tr>
<td>th:replace</td>
<td>replace</td>
<td><div th:replace="fragments/header :: title"></div></td>
</tr>

<tr>
<td>th:selected</td>
<td>select</td>
<td>th:selected=&ldquo;(${xxx.id} == ${configObj.id})&rdquo;</td>
</tr>

<tr>
<td>th:src</td>
<td>src</td>
<td><img th:src="@{/img/logo.png}" /></td>
</tr>

<tr>
<td>th:action</td>
<td>form</td>
<td><form th:action="@{/submit(type=1)}" /></td>
</tr>

<tr>
<td>th:remove</td>
<td>remove</td>
<td><tr th:remove="all"></td>
</tr>

<tr>
<td>th:attr</td>
<td>set attrabute</td>
<td><p th:attr="src=@{/img/a.jpg}, title=${title}">content</p></td>
</tr>
</tbody>
</table>
                        </div>

                        


                        


                        <div class="post-meta meta-tags">
                            
                            <ul class="clearfix">
                                
                                <li><a href="https://otswang.gitee.io/hugo/tags/%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E">模板引擎</a></li>
                                
                                <li><a href="https://otswang.gitee.io/hugo/tags/thymeleaf">Thymeleaf</a></li>
                                
                            </ul>
                            
                        </div>
                    </article>
                    
    

    
    
                </div>
            </div>
            <div id="secondary">

    <section class="widget">
        <form id="search" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://otswang.gitee.io/hugo/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/middle_tools/kafka/" title="Kafka">Kafka</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/middle_tools/zk_starter/" title="Zookeeper Starter">Zookeeper Starter</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/java/javafx_starter/" title="Java Fx 入门学习">Java Fx 入门学习</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/other/codec/" title="常用加密/签名算法">常用加密/签名算法</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/other/docker/" title="Docker学习">Docker学习</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/webapp/react_starter/" title="React 从入门到入门">React 从入门到入门</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/lang/csharpe_starter/" title="C#语言从入门到入门">C#语言从入门到入门</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/java/java8time/" title="Java checklist">Java checklist</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/other/keyboard/" title="快捷键记录">快捷键记录</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/post/other/vim/" title="vim 使用记录">vim 使用记录</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/algorithm/">algorithm(4)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/design/">design(7)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/doc/">doc(2)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/go/">go(3)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java/">java(7)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java-java8inaction/">java-java8inaction(11)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java-juc/">java-juc(3)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java-jvm/">java-jvm(2)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java-spring/">java-spring(2)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/java-thinkinginjava/">java-thinkinginjava(11)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/middletools/">middletools(9)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/other/">other(24)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/qt/">qt(2)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/smallquickappweb/">smallquickappweb(4)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/webapp/">webapp(1)</a>
    </li>
    
    <li>
        <a href="https://otswang.gitee.io/hugo/categories/%E5%B0%8F%E4%BC%97%E8%AF%AD%E8%A8%80%E4%B8%80%E7%9E%A5/">小众语言一瞥(4)</a>
    </li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="https://otswang.gitee.io/hugo/tags/c/">c#</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/checklist/">checklist</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/codec/">codec</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/docker/">docker</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/elk/">elk</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/emmet/">emmet</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/file/">file</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/freemarker/">freemarker</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/git/">git</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/go/">go</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/http/">http</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/interview/">interview</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/java/">java</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/javascript/">javascript</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/juc/">juc</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/jvm/">jvm</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/keyboard/">keyboard</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/linux/">linux</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/lua/">lua</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/manjaro/">manjaro</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/map/">map</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/markdown/">markdown</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/mq/">mq</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/mybatis/">mybatis</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/mycat/">mycat</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/mysql/">mysql</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/nginx/">nginx</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/qt/">qt</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/react/">react</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/redis/">redis</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/rust/">rust</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/spring/">spring</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/springboot/">springboot</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/stream/">stream</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/tcp/">tcp</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/thymeleaf/">thymeleaf</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/tree/">tree</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/uml/">uml</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/vim/">vim</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/vlang/">vlang</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/vue/">vue</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/zookeeper/">zookeeper</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E4%BD%8D%E8%BF%90%E7%AE%97/">位运算</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E5%8D%8F%E8%AE%AE/">协议</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/">多线程</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E5%B9%B6%E5%8F%91%E9%9B%86%E5%90%88/">并发集合</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E5%BF%AB%E5%BA%94%E7%94%A8/">快应用</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E6%97%B6%E9%97%B4%E7%B1%BB/">时间类</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E6%A8%A1%E6%9D%BF%E5%BC%95%E6%93%8E/">模板引擎</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E7%AE%97%E6%B3%95/">算法</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E7%BC%96%E7%A8%8B/">编程</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E7%BC%96%E7%A8%8B%E8%A7%84%E8%8C%83/">编程规范</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E8%AE%BE%E8%AE%A1/">设计</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E9%99%90%E6%B5%81/">限流</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/">面向对象</a>
    
    <a href="https://otswang.gitee.io/hugo/tags/%E9%9D%A2%E8%AF%95/">面试</a>
    
</div>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://otswang.gitee.io/hugo/index.xml">文章 RSS</a></li>
        </ul>
    </section>

    

</div>
        </div>
    </div>
</div>
<footer id="footer">
    <div class="container">
        &copy; 2020 <a href="https://otswang.gitee.io/hugo/">The Sky of OtsWang By OtsWang</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/Dudiao137/maupassant-hugo" target="_blank">maupassant-ots</a>.
        
    </div>
</footer>


    <script type="text/javascript">
    
    (function(){
        $("pre code").parent().addClass("line-numbers")
    }())

    window.MathJax = {
        tex2jax: {
            inlineMath: [ ['$','$'] ],
            processEscapes: true
        }
    };
    </script>
    <script type="text/javascript" src="/hugo/js/prism.js" async="true"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src="/hugo/js/totop.js?v=0.0.0" async=""></script>







 
 <script src="https://mermaidjs.github.io/scripts/mermaid.min.js"></script>
 <script>
       mermaid.initialize({ startOnLoad: true });
 </script>
</body>
</html>
